package com.zzy.forum.congfig;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Date;

@Configuration
public class MybatisPlusConfig {
    @Bean
    public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor(){
        return new OptimisticLockerInnerInterceptor();
    }
    @Bean
    public MetaObjectHandler metaObjectHandler(){
        return new MetaObjectHandler() {
            @Override
            public void insertFill(MetaObject metaObject) {
                this.setFieldValByName("createTime",new Date(),metaObject);
                this.setFieldValByName("is_del",0,metaObject);
                this.setFieldValByName("id",1,metaObject);
                this.setFieldValByName("isActive",true,metaObject);
            }

            @Override
            public void updateFill(MetaObject metaObject) {

            }
        };
    }
    @Bean
    public LogicDeleteByIdWithFill logicDeleteByIdWithFill(){
        return new LogicDeleteByIdWithFill();
    }
}
